package io.github.talelin.latticy.controller.api;


import io.github.talelin.latticy.dto.wxUser.WxUserDTO;
import io.github.talelin.latticy.dto.wxUser.WxUserUpdateDTO;
import io.github.talelin.latticy.model.WxUserDO;
import io.github.talelin.latticy.service.WxUserService;
import io.github.talelin.latticy.vo.CreatedVO;
import io.github.talelin.latticy.vo.UnifyResponseVO;
import io.github.talelin.latticy.vo.UpdatedVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Positive;

/**
* @author generator@lms
* @since 2021-04-20
*/
@RestController
@RequestMapping("/api/user")
@Validated
public class WxUserApiController {
    @Autowired
    private WxUserService wxUserService;

    @PostMapping("/login")
    public UnifyResponseVO<WxUserDO> login(@RequestBody @Validated WxUserDTO dto) {
        System.out.println(dto.getNativePlace());
        WxUserDO wxUser = wxUserService.login(dto);
        return new UnifyResponseVO<>(wxUser);
    }

    @PostMapping("/update")
    public UpdatedVO update(@RequestBody @Validated WxUserUpdateDTO dto) {
        wxUserService.updateInfo(dto);
        return new UpdatedVO("用户信息保存成功！");
    }

}
